<template>
  <div class="list-table">
    <!--    <div class="area-header">-->
    <!--      <span class="area-header-title">{{ $t('填报数据审核') }}</span>-->
    <!--    </div>-->
    <el-form ref="queryForm" :model="queryParams" :inline="true" @submit.native.prevent>
      <el-form-item :label="$t('管理人名称')" prop="gpName">
        <el-input
          v-model="queryParams.gpName"
          :placeholder="$t('管理人名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" tooltip-effect="darkTable" :data="bfPortalDataList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('管理人名称')" align="center" prop="gpName" />
      <el-table-column :label="$t('年份')" align="center" prop="year" width="130" />
      <el-table-column :label="$t('报告期类型')" align="center" prop="type" width="130" />
      <el-table-column :label="$t('提交时间')" align="center" prop="submitTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('审核状态')" align="center" prop="status" width="130" />
      <el-table-column :label="$t('审核人')" align="center" prop="applyUserName" width="120" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="280">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['bfPortal:TB:edit']"
            size="small"
            type="text"
            icon="el-icon-s-custom"
            @click="asyncPortalTBData(scope.row)"
          >{{ $t('审核') }}
          </el-button>
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['bfPortal:TB:edit']"
            size="small"
            type="text"
            icon="el-icon-s-custom"
            @click="rejectPortal(scope.row)"
          >{{ $t('驳回') }}
          </el-button>
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['bfPortal:TB:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="viewTBData(scope.row, 'edit')"
          >{{ $t('检查') }}
          </el-button>
          <el-button
            v-if="scope.row.status === '待审核'"
            v-hasPermi="['bfPortal:TB:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="comparison(scope.row)"
          >{{ $t('比对') }}
          </el-button>
          <el-button
            v-if="scope.row.status === '审核通过'"
            v-hasPermi="['bfPortal:TB:view']"
            size="small"
            type="text"
            icon="el-icon-view"
            @click="viewTBData(scope.row, 'view')"
          >{{ $t('查看') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :visible.sync="rejectOpen" :title="$t('意见回复')" :close-on-click-modal="false" width="50%">
      <el-form ref="rejectForm" :model="form" class="dataForm" :inline="true" :rules="rejectFormRules">
        <el-row>
          <el-col :span="24">
            <el-input v-model="form.commentResponse" type="textarea" :placeholder="$t('意见回复')" show-word-limit maxlength="1000" />
          </el-col>
        </el-row>
        <FileTable :list.sync="form.fileList" data-type="bf_portal_data" business-type="bf" :main-body-vue-show="false" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelReject">{{ $t('取消') }}</el-button>
        <el-button type="primary" @click="rejectPortalData(form)">{{ $t('确定') }}</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="comparisonOpen" :title="$t('比对')" custom-class="dialogForm" :close-on-click-modal="false" :lock-scroll="false" append-to-body>
      <comparison ref="comparison" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listBfPortalTBData,
  getPortalToken,
  asyncPortalTBData,
  rejectPortalTBData
} from '@/api/bf/portal/bfPortalData'
import comparison from '@/views/bf/portal/comparison/gpCompanyInfo.vue'

export default {
  components: {
    comparison
  },
  data() {
    return {
      // 填报数据遮罩层
      loading: true,
      // 填报数据总条数
      total: 0,
      // 子基金填报-填报数据审核表格数据
      bfPortalDataList: [],
      // 审批状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        dataType: 'TB',
        gpName: undefined,
        year: undefined,
        type: undefined,
        status: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 驳回意见
      rejectOpen: false,
      comparisonOpen: false,
      // 驳回表单
      rejectForm: {
        gpName: undefined,
        reportId: undefined,
        year: undefined,
        type: undefined,
        status: undefined,
        commentResponse: undefined,
        fileList: []
      },
      rejectFormRules: {
      }
    }
  },
  created() {
    this.getList()
    this.getDicts('work_flow_status').then(response => {
      this.statusOptions = response.data
    })
  },
  methods: {
    /** 查询填报数据审核列表 */
    getList() {
      this.loading = true
      listBfPortalTBData(this.queryParams).then(response => {
        this.bfPortalDataList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 审批状态字典翻译
    statusFormat(row) {
      return this.selectDictLabel(this.statusOptions, row.status)
    },
    // 表单重置
    reset() {
      this.form = {
        gpName: undefined,
        reportId: undefined,
        year: undefined,
        type: undefined,
        status: undefined,
        commentResponse: undefined,
        fileList: []
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    // 查看数据 - 填报数据
    viewTBData(row, view) {
      // 获取临时token
      getPortalToken().then(res => {
        window.open(
          process.env.VUE_APP_BASE_BF_PORTAL_URL + '/login?tempToken=' + res.data.token + '&suffix=' + res.data.time + '&gpId=' +
          row.gpId + '&reportId=' + row.reportId + '&btnView=' + view)
      })
    },
    // 入库操作 - 填报
    asyncPortalTBData(row) {
      if (row.id !== '' && row.id !== undefined) {
        this.$confirm(this.$t('审核通过之后，数据会同步到对应数据内，是否确认通过?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(() => {
          this.loading = true
        }).then(function() {
          return asyncPortalTBData(row.id).catch(() => {
            this.loading = false
          })
        }).then(() => {
          this.getList()
          this.msgSuccess(this.$t('审核通过，数据同步成功!'))
        }).catch(function() {
          this.msgError(this.$t('审核未通过，数据同步失败!'))
        })
      }
    },
    // 驳回数据
    rejectPortalData(row) {
      if (row.id !== '' && row.id !== undefined) {
        this.rejectOpen = false
        this.loading = true
        rejectPortalTBData(row).then(() => {
          this.getList()
          this.msgSuccess(this.$t('已驳回!'))
        }).catch(() => {
          this.getList()
        })
      }
    },
    rejectPortal(row) {
      if (row.id !== '' && row.id !== undefined) {
        this.rejectOpen = true
        this.form = row
      }
    },
    cancelReject() {
      this.rejectOpen = false
    },
    /** saas与GP比对 **/
    comparison(row) {
      this.comparisonOpen = true
      this.$nextTick(() => {
        this.$refs.comparison.init(row)
      })
    }
  }
}
</script>
